package com.bjpowernode.rbac.web.controller;

import com.bjpowernode.rbac.anno.RequestPermission;
import com.bjpowernode.rbac.entity.Department;
import com.bjpowernode.rbac.query.QueryObject;
import com.bjpowernode.rbac.service.DepartmentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author jy
 * @version 1.0
 * @date 2022/2/7 19:13
 */
@Controller
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject queryObject){
        //调用业务层获取数据
        PageInfo<Department> pageInfo = departmentService.selectDepartmentByCondition(queryObject);
        //传到页面
        model.addAttribute("pageInfo",pageInfo);
        //跳转到页面
        return "department/list";
    }

    @RequestMapping("/saveOrUpdate")
    @RequestPermission({"部门新增和编辑权限","department:saveOrUpdate"})
    public String saveOrUpdate(Department department){
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list";
    }

    @RequestMapping("/delete")
    @RequestPermission({"部门删除权限","department:delete"})
    public String delete(Long id){
        departmentService.delete(id);
        return "redirect:/department/list";
    }
}
